#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        int n = s.size(), len = 0;
        int left = 0, right = 0;
        int hash[256] = { 0 };
        while (right < n)
        {
            hash[s[right]]++;
            while (hash[s[right]] == 2)
            {
                hash[s[left]]--;
                left++;
            }
            len = max(len, right - left + 1);
            right++;
        }
        // return len == INT_MIN ? 0:len;
        return len;
    }
};